
rm(list = ls())
library(foreign);
install.packages("extrafont", dependencies=TRUE);library(extrafont)
install.packages("RColorBrewer", dependencies=TRUE);library(RColorBrewer)
install.packages("xts", dependencies=TRUE);library(xts)


data<-read.dta("Data.dta");head(data);attach(data)

date<- zoo(matrix(0, nrow=30, ncol=0), as.Date("2011-01-01") + 0:364);time<-seq(48,298,by=1)

#################
### Figure 1a ###
#################

par(family="Palatino")   
layout(rbind(1,2), heights=c(7,1))
par(mai=c(0.65,0.65,0.2,0.1),family="Palatino",oma=c(2,2,2,2),mgp=c(2, 0.5, 0),cex.lab=1.2,cex.axis=.8)
plot(time,LibRebTOLibGov,type="l",lwd=3,xaxt="n",yaxt="n",xlab=expression(bold(Days)),col="black",ylab=expression(bold(Scaled)~bold(Event)~bold(Data)),ylim=c(min(LibRebTOLibGov),(min(LibRebTOLibGov)*-1)))
lines(time, LibGovTOLibReb,type="l",lwd=2,col="gray")
axis(side=1, at=c(60,91,121,152,182,213,244,274,303),las=0,labels=c("03/01","04/01","05/01","06/01","07/01","08/01","09/01","10/01","25/10"))
axis(side=2, at=c(min(LibRebTOLibGov),(min(LibRebTOLibGov)*-1)),las=2,labels=c(round(min(LibRebTOLibGov),2),round((min(LibRebTOLibGov)*-1),2)))
par(mai=c(0,0,0,0),family="Palatino")
plot.new()
legend(x="center",title="",horiz=TRUE,legend=c("Rebels -> Gov.","Gov. -> Rebels"),box.col="gray", col=c("black","gray"),lty=c(1,1),lwd=c(3,2))

#################
### Figure 1b ###
#################

par(family="Palatino")   
layout(rbind(1,2), heights=c(7,1))
par(mai=c(0.65,0.65,0.2,0.1),family="Palatino",oma=c(2,2,2,2),mgp=c(2, 0.5, 0),cex.lab=1.2,cex.axis=.8)
plot(time,USGovTOLibReb,type="l",lwd=3,xaxt="n",yaxt="n",xlab=expression(bold(Days)),col="black",ylab=expression(bold(Scaled)~bold(Event)~bold(Data)),ylim=c(min(USGovTOLibGov),(min(USGovTOLibGov)*-1)))
lines(time, USGovTOLibGov,type="l",lwd=2,col="gray")
axis(side=1, at=c(60,91,121,152,182,213,244,274,303),las=0,labels=c("03/01","04/01","05/01","06/01","07/01","08/01","09/01","10/01","25/10"))
axis(side=2, at=c(min(USGovTOLibGov),(min(USGovTOLibGov)*-1)),las=2,labels=c(round(min(USGovTOLibGov),2),round((min(USGovTOLibGov)*-1),2)))
par(mai=c(0,0,0,0),family="Palatino")
plot.new()
legend(x="center",title="",horiz=TRUE,legend=c("US -> Rebels","US -> Gov."),box.col="gray", col=c("black","gray"),lty=c(1,1),lwd=c(3,2))


#################
### Figure 2  ###
#################

tw1<-sum(Twitter1_count)
tw2<-sum(Twitter2_count)
tw3<-sum(Twitter3_count)
tw4<-sum(Twitter4_count)
actionstype<-seq(1,4,by=1);
a<-rbind(actionstype[1], tw1)
b<-rbind(actionstype[2], tw2)
c<-rbind(actionstype[3], tw3)
d<-rbind(actionstype[4], tw4)
x<-as.table(cbind(a,b,c,d))

lightgray<-"#cccccc";darkgray<-"#3d3d3d";gray<-"#d3d3d3"

time<-seq(48,304,by=1)

par(family="Palatino")   
layout(matrix(c(1,2,3,3), ncol=1, byrow=TRUE), heights=c(4, 1))
par(mai=c(0.65,0.65,0.2,0.1),family="Palatino",oma=c(2,2,2,2),mgp=c(2, 0.5, 0),cex.lab=1.2,cex.axis=.8)
barplot(x[-1,], col=c("black",darkgray,gray,lightgray),beside=TRUE, names=c("Internat. Support","Battlef. Success","Clarify Aims"," Gov. Atrocities"), , ylim=c(0,120))
par(mai=c(0,0,0,0),family="Palatino")
plot.new()
legend(x="center",title="",horiz=TRUE,legend=c("Internat. Support","Battlef. Success","Clarify Aims"," Gov. Atrocities"),box.col="gray", col=c("black",darkgray,gray,lightgray),lty=c(1,1,1,1),lwd=c(3,3,3,3))







